package org.dfl.plugin.editor.parts;

import org.dfl.plugin.editor.commands.ShapeDeleteCommand;
import org.dfl.plugin.editor.model.DflDiagram;
import org.dfl.plugin.editor.model.InputPlaceModelElement;
import org.dfl.plugin.editor.model.OutputPlaceModelElement;
import org.dfl.plugin.editor.model.Shape;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.ComponentEditPolicy;
import org.eclipse.gef.requests.GroupRequest;


/**
 * This edit policy enables the removal of a Shapes instance from its container.
 * @author Piotr Wlodarczyk
 */
public class ShapeComponentEditPolicy extends ComponentEditPolicy {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.gef.editpolicies.ComponentEditPolicy#createDeleteCommand(org.eclipse.gef.requests.GroupRequest)
	 */
	protected Command createDeleteCommand(GroupRequest deleteRequest) {
		Object parent = getHost().getParent().getModel();
		Object child = getHost().getModel();	
		if (parent instanceof DflDiagram && child instanceof Shape
			&& !(child instanceof InputPlaceModelElement) // nie mozna usunac wejscia i wyjscia!  
			&& !(child instanceof OutputPlaceModelElement) ){
			return new ShapeDeleteCommand((DflDiagram) parent, (Shape) child);
		}
		return super.createDeleteCommand(deleteRequest);
	}
	
}